import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class StringExtractor {

    private static final char QUOTE = '"';  // 双引号字符
    private static final char BACKSLASH = '\\';  // 反斜杠字符

    public static void main(String[] args) {
        String fileName = "sourceCode.txt";  // 假设源代码文件名为sourceCode.txt
        try {
            extractStringsFromFile(fileName);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void extractStringsFromFile(String fileName) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader(fileName));
        int currentChar;
        StringBuilder currentString = new StringBuilder();
        boolean insideString = false;
        boolean escapeNext = false; // 标记下一个字符是否为转义字符

        while ((currentChar = reader.read()) != -1) {
            char c = (char) currentChar;

            if (insideString) {
                if (escapeNext) {
                    // 如果上一个字符是反斜杠，则当前字符会被转义
                    currentString.append(c);
                    escapeNext = false; // 重置转义标记
                } else if (c == BACKSLASH) {
                    // 遇到反斜杠时，标记下一个字符为转义字符
                    escapeNext = true;
                } else if (c == QUOTE) {
                    // 遇到结束的双引号，提取字符串并重置
                    System.out.println("提取的字符串: " + currentString.toString());
                    currentString.setLength(0);  // 清空字符串缓存
                    insideString = false;  // 结束字符串读取
                } else {
                    // 普通字符，添加到当前字符串中
                    currentString.append(c);
                }
            } else {
                if (c == QUOTE) {
                    // 遇到开始的双引号，进入字符串提取模式
                    insideString = true;
                }
            }
        }

        reader.close();
    }
}
